package jehc.cloud.gen.web;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jehc.cloud.common.annotation.NeedLoginUnAuth;
import jehc.cloud.common.base.BasePage;
import jehc.cloud.common.base.BaseResult;
import jehc.cloud.common.base.BaseSearch;
import jehc.cloud.common.util.StringUtil;
import jehc.cloud.gen.base.BaseAction;
import jehc.cloud.gen.base.BaseAction;
import jehc.cloud.gen.model.XtGeneratorForbidtable;
import jehc.cloud.gen.service.XtGeneratorForbidtableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageInfo;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Desc 禁止使用代码生成器生成模块
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/xtGeneratorForbidtable")
@Api(value = "禁止使用代码生成器生成API",description = "禁止使用代码生成器生成API")
public class XtGeneratorForbidtableController extends BaseAction {
	@Autowired
	private XtGeneratorForbidtableService xtGeneratorForbidtableService;

	/**
	 * 列表页面
	 * @param model
	 * @return
	 */
	@ApiOperation(value="列表页面", notes="列表页面")
	@RequestMapping(value="/pageList")
	public ModelAndView pageList(Model model) {
		return new ModelAndView("xt-generator-forbidtable/xt-generator-forbidtable-list");
	}

	/**
	 * 新增页面
	 * @param model
	 * @return
	 */
	@ApiOperation(value="新增页面", notes="新增页面")
	@RequestMapping(value="/pageAdd")
	public ModelAndView pageAdd(Model model) {
		return new ModelAndView("xt-generator-forbidtable/xt-generator-forbidtable-add");
	}

	/**
	 * 编辑页面
	 * @param model
	 * @param xt_generator_f_id
	 * @return
	 */
	@ApiOperation(value="编辑页面", notes="编辑页面")
	@RequestMapping(value="/pageUpdate")
	public ModelAndView pageUpdate(Model model,String xt_generator_f_id) {
		model.addAttribute("xt_generator_f_id",xt_generator_f_id);
		return new ModelAndView("xt-generator-forbidtable/xt-generator-forbidtable-update");
	}

	/**
	 * 详情页面
	 * @param model
	 * @param xt_generator_f_id
	 * @return
	 */
	@ApiOperation(value="详情页面", notes="详情页面")
	@RequestMapping(value="/pageDetail")
	public ModelAndView pageDetail(Model model,String xt_generator_f_id) {
		model.addAttribute("xt_generator_f_id",xt_generator_f_id);
		return new ModelAndView("xt-generator-forbidtable/xt-generator-forbidtable-detail");
	}

	/**
	* 加载初始化列表数据并分页
	* @param baseSearch
	*/
	@NeedLoginUnAuth
	@PostMapping(value="/list")
	@ApiOperation(value="查询列表并分页", notes="查询列表并分页")
	@ResponseBody
	public BasePage getXtGeneratorForbidtableListByCondition(@RequestBody(required=true)BaseSearch baseSearch){
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		List<XtGeneratorForbidtable> xt_Generator_ForbidtableList = xtGeneratorForbidtableService.getXtGeneratorForbidtableListByCondition(condition);
		PageInfo<XtGeneratorForbidtable> page = new PageInfo<XtGeneratorForbidtable>(xt_Generator_ForbidtableList);
		return outPageBootStr(page,baseSearch);
	}
	/**
	* 单条记录
	* @param xt_generator_forbidtable_id
	*/
	@NeedLoginUnAuth
	@GetMapping(value="/get/{xt_generator_forbidtable_id}")
	@ApiOperation(value="查询单个记录", notes="查询单个记录")
	@ResponseBody
	public BaseResult getXtGeneratorForbidtableById(@PathVariable("xt_generator_forbidtable_id") String xt_generator_forbidtable_id){
		XtGeneratorForbidtable xt_Generator_Forbidtable = xtGeneratorForbidtableService.getXtGeneratorForbidtableById(xt_generator_forbidtable_id);
		return outDataStr(xt_Generator_Forbidtable);
	}
	/**
	* 添加
	* @param xtGeneratorForbidtable
	*/
	@PostMapping(value="/add")
	@ApiOperation(value="创建", notes="创建")
	@ResponseBody
	public BaseResult addXtGeneratorForbidtable(@RequestBody XtGeneratorForbidtable xtGeneratorForbidtable){
		int i = 0;
		if(null != xtGeneratorForbidtable){
			xtGeneratorForbidtable.setXt_generator_f_id(toUUID());
			xtGeneratorForbidtable.setXt_generator_f_ctime(getSimpleDateFormat());
			xtGeneratorForbidtable.setXt_userinfo_id(getXtUid());
			i=xtGeneratorForbidtableService.addXtGeneratorForbidtable(xtGeneratorForbidtable);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
	/**
	* 修改
	* @param xtGeneratorForbidtable
	*/
	@PutMapping(value="/update")
	@ApiOperation(value="编辑", notes="编辑")
	@ResponseBody
	public BaseResult updateXtGeneratorForbidtable(@RequestBody XtGeneratorForbidtable xtGeneratorForbidtable){
		int i = 0;
		if(null != xtGeneratorForbidtable){
			xtGeneratorForbidtable.setXt_generator_f_mtime(getSimpleDateFormat());
			xtGeneratorForbidtable.setXt_userinfo_id(getXtUid());
			i=xtGeneratorForbidtableService.updateXtGeneratorForbidtable(xtGeneratorForbidtable);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
	/**
	* 删除
	* @param xt_generator_forbidtable_id
	*/
	@DeleteMapping(value="/delete")
	@ApiOperation(value="删除", notes="删除")
	@ResponseBody
	public BaseResult delXtGeneratorForbidtable(String xt_generator_forbidtable_id){
		int i = 0;
		if(!StringUtil.isEmpty(xt_generator_forbidtable_id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("xt_generator_f_id",xt_generator_forbidtable_id.split(","));
			i=xtGeneratorForbidtableService.delXtGeneratorForbidtable(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
